package com.zhaolixiang.camera02

import android.app.Activity
import android.content.Context
import android.opengl.ETC1.getHeight
import android.opengl.ETC1.getWidth
import android.util.Size
import com.zhaolixiang.camera02.ttt.CompareSizesByArea
import android.graphics.ImageFormat
import android.hardware.camera2.CameraCharacteristics
import android.hardware.camera2.CameraManager
import java.util.*
import java.util.Arrays.asList




/**
 * Created by Administrator on 2017/12/27.
 */
class ttt {
    fun tttttt(activity:Activity){
        val cameraManager = activity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
        // 获取指定摄像头的特性
        val characteristics
                = cameraManager.getCameraCharacteristics("");
        // 获取摄像头支持的配置属性
        val map = characteristics.get(
                CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        val largest = Collections.max(
                map.getOutputSizes(ImageFormat.JPEG) as Collection<Size>,
                CompareSizesByArea())
    }
    internal inner class CompareSizesByArea : Comparator<Size> {
        override fun compare(lhs: Size, rhs: Size): Int {
            // 强转为long保证不会发生溢出
            return java.lang.Long.signum(lhs.getWidth() as Long * lhs.getHeight() - rhs.getWidth() as Long * rhs.getHeight())
        }
    }
}